package com.net.xpay.admin.controller.admin;

import com.net.common.model.ResultData;
import com.net.xpay.common.domain.SiteConfig;
import com.net.xpay.common.service.SiteConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/site-config")
@Api(tags = "运营/网站配置信息", description = "运营/网站配置信息")
public class AdminSiteConfigController {
    @Autowired
    private SiteConfigService siteConfigService;

    @ApiOperation("查詢网站配置信息")
    @GetMapping
    @PreAuthorize("hasAnyRole('ADMIN', 'site-config::get')")
    public ResultData<SiteConfig> getSiteConfig() {
        SiteConfig siteConfig = siteConfigService.findSiteConfig();
        return new ResultData<>(siteConfig);
    }

    @ApiOperation("新增网站配置信息")
    @PostMapping
    @PreAuthorize("hasAnyRole('ADMIN', 'site-config::add')")
    public ResultData<Boolean> addSiteConfig(@RequestBody SiteConfig siteConfig) {
        siteConfigService.addSiteConfig(siteConfig);
        return new ResultData<>(true);
    }

    @ApiOperation("更新网站配置信息")
    @PutMapping
    @PreAuthorize("hasAnyRole('ADMIN', 'site-config::update')")
    public ResultData<SiteConfig> updateConfig(@RequestBody SiteConfig siteConfig) {
        SiteConfig updateSiteConfig = siteConfigService.updateSiteConfig(siteConfig);
        return new ResultData<>(updateSiteConfig);
    }

}
